namespace SilverSea.Registration
{
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Windows.Forms;

    public class SerialBox : UserControl
    {
        private IContainer components;
        private TextBox textBox1;
        private TextBox textBox2;
        private TextBox textBox3;
        private TextBox textBox4;
        private TextBox textBox5;
        private TextBox textBox6;
        private TextBox textBox7;
        private TextBox textBox8;

        public SerialBox()
        {
            this.InitializeComponent();
        }

        public void Clear()
        {
            this.textBox1.Text = "";
            this.textBox2.Text = "";
            this.textBox3.Text = "";
            this.textBox4.Text = "";
            this.textBox5.Text = "";
            this.textBox6.Text = "";
            this.textBox7.Text = "";
            this.textBox8.Text = "";
        }

        protected override void Dispose(bool disposing)
        {
            if (disposing && (this.components != null))
            {
                this.components.Dispose();
            }
            base.Dispose(disposing);
        }

        private void InitializeComponent()
        {
            this.textBox1 = new TextBox();
            this.textBox2 = new TextBox();
            this.textBox3 = new TextBox();
            this.textBox4 = new TextBox();
            this.textBox5 = new TextBox();
            this.textBox6 = new TextBox();
            this.textBox7 = new TextBox();
            this.textBox8 = new TextBox();
            base.SuspendLayout();
//            this.textBox1.CharacterCasing = CharacterCasing.Upper;
            this.textBox1.Font = new Font("Microsoft Sans Serif", 8.25f, FontStyle.Regular, GraphicsUnit.Point, 0);
            this.textBox1.Location = new Point(4, 3);
            this.textBox1.MaxLength = 5;
            this.textBox1.Name = "textBox1";
            this.textBox1.Size = new Size(50, 20);
            this.textBox1.TabIndex = 0;
            this.textBox1.KeyPress += new KeyPressEventHandler(this.textBox_KeyPress);
            this.textBox1.TextChanged += new EventHandler(this.textBox_TextChanged);
            this.textBox2.CharacterCasing = CharacterCasing.Upper;
            this.textBox2.Font = new Font("Microsoft Sans Serif", 8.25f, FontStyle.Regular, GraphicsUnit.Point, 0);
            this.textBox2.Location = new Point(60, 3);
            this.textBox2.MaxLength = 5;
            this.textBox2.Name = "textBox2";
            this.textBox2.Size = new Size(50, 20);
            this.textBox2.TabIndex = 1;
            this.textBox2.KeyPress += new KeyPressEventHandler(this.textBox_KeyPress);
            this.textBox2.TextChanged += new EventHandler(this.textBox_TextChanged);
            this.textBox3.CharacterCasing = CharacterCasing.Upper;
            this.textBox3.Font = new Font("Microsoft Sans Serif", 8.25f, FontStyle.Regular, GraphicsUnit.Point, 0);
            this.textBox3.Location = new Point(0x74, 3);
            this.textBox3.MaxLength = 5;
            this.textBox3.Name = "textBox3";
            this.textBox3.Size = new Size(50, 20);
            this.textBox3.TabIndex = 2;
            this.textBox3.KeyPress += new KeyPressEventHandler(this.textBox_KeyPress);
            this.textBox3.TextChanged += new EventHandler(this.textBox_TextChanged);
            this.textBox4.CharacterCasing = CharacterCasing.Upper;
            this.textBox4.Font = new Font("Microsoft Sans Serif", 8.25f, FontStyle.Regular, GraphicsUnit.Point, 0);
            this.textBox4.Location = new Point(0xac, 3);
            this.textBox4.MaxLength = 5;
            this.textBox4.Name = "textBox4";
            this.textBox4.Size = new Size(50, 20);
            this.textBox4.TabIndex = 3;
            this.textBox4.KeyPress += new KeyPressEventHandler(this.textBox_KeyPress);
            this.textBox4.TextChanged += new EventHandler(this.textBox_TextChanged);
            this.textBox5.CharacterCasing = CharacterCasing.Upper;
            this.textBox5.Font = new Font("Microsoft Sans Serif", 8.25f, FontStyle.Regular, GraphicsUnit.Point, 0);
            this.textBox5.Location = new Point(0xe4, 3);
            this.textBox5.MaxLength = 5;
            this.textBox5.Name = "textBox5";
            this.textBox5.Size = new Size(50, 20);
            this.textBox5.TabIndex = 4;
            this.textBox5.KeyPress += new KeyPressEventHandler(this.textBox_KeyPress);
            this.textBox5.TextChanged += new EventHandler(this.textBox_TextChanged);
            this.textBox6.CharacterCasing = CharacterCasing.Upper;
            this.textBox6.Font = new Font("Microsoft Sans Serif", 8.25f, FontStyle.Regular, GraphicsUnit.Point, 0);
            this.textBox6.Location = new Point(0x11c, 3);
            this.textBox6.MaxLength = 5;
            this.textBox6.Name = "textBox6";
            this.textBox6.Size = new Size(50, 20);
            this.textBox6.TabIndex = 5;
            this.textBox6.KeyPress += new KeyPressEventHandler(this.textBox_KeyPress);
            this.textBox6.TextChanged += new EventHandler(this.textBox_TextChanged);
            this.textBox7.CharacterCasing = CharacterCasing.Upper;
            this.textBox7.Font = new Font("Microsoft Sans Serif", 8.25f, FontStyle.Regular, GraphicsUnit.Point, 0);
            this.textBox7.Location = new Point(340, 3);
            this.textBox7.MaxLength = 5;
            this.textBox7.Name = "textBox7";
            this.textBox7.Size = new Size(50, 20);
            this.textBox7.TabIndex = 6;
            this.textBox7.KeyPress += new KeyPressEventHandler(this.textBox_KeyPress);
            this.textBox7.TextChanged += new EventHandler(this.textBox_TextChanged);
            this.textBox8.CharacterCasing = CharacterCasing.Upper;
            this.textBox8.Font = new Font("Microsoft Sans Serif", 8.25f, FontStyle.Regular, GraphicsUnit.Point, 0);
            this.textBox8.Location = new Point(0x18c, 3);
            this.textBox8.MaxLength = 5;
            this.textBox8.Name = "textBox8";
            this.textBox8.Size = new Size(50, 20);
            this.textBox8.TabIndex = 7;
            this.textBox8.KeyPress += new KeyPressEventHandler(this.textBox_KeyPress);
            this.textBox8.TextChanged += new EventHandler(this.textBox_TextChanged);
            base.AutoScaleDimensions = new SizeF(6f, 13f);
//            base.AutoScaleMode = AutoScaleMode.Font;
            base.Controls.Add(this.textBox8);
            base.Controls.Add(this.textBox7);
            base.Controls.Add(this.textBox6);
            base.Controls.Add(this.textBox5);
            base.Controls.Add(this.textBox4);
            base.Controls.Add(this.textBox3);
            base.Controls.Add(this.textBox2);
            base.Controls.Add(this.textBox1);
            base.Name = "SerialBox";
            base.Size = new Size(0x1c3, 0x1a);
            base.ResumeLayout(false);
            base.PerformLayout();

        }

        private void textBox_KeyPress(object sender, KeyPressEventArgs e)
        {
            if ((!char.IsDigit(e.KeyChar) && !char.IsControl(e.KeyChar)) && !char.IsLetter(e.KeyChar))
            {
                e.Handled = true;
            }
        }

        private void textBox_TextChanged(object sender, EventArgs e)
        {
            TextBox box = (TextBox) sender;
            if (box.Text.Length == 5)
            {
                if (box.Name == "textBox1")
                {
                    this.textBox2.Focus();
                }
                else if (box.Name == "textBox2")
                {
                    this.textBox3.Focus();
                }
                else if (box.Name == "textBox3")
                {
                    this.textBox4.Focus();
                }
                else if (box.Name == "textBox4")
                {
                    this.textBox5.Focus();
                }
                else if (box.Name == "textBox5")
                {
                    this.textBox6.Focus();
                }
                else if (box.Name == "textBox6")
                {
                    this.textBox7.Focus();
                }
                else if (box.Name == "textBox7")
                {
                    this.textBox8.Focus();
                }
            }
        }

        public bool ReadOnly
        {
            set
            {
                this.textBox1.ReadOnly = value;
                this.textBox2.ReadOnly = value;
                this.textBox3.ReadOnly = value;
                this.textBox4.ReadOnly = value;
                this.textBox5.ReadOnly = value;
                this.textBox6.ReadOnly = value;
                this.textBox7.ReadOnly = value;
                this.textBox8.ReadOnly = value;
            }
        }

        public override string Text
        {
            get
            {
                return (this.textBox1.Text + this.textBox2.Text + this.textBox3.Text + this.textBox4.Text + this.textBox5.Text + this.textBox6.Text + this.textBox7.Text + this.textBox8.Text);
            }
            set
            {
                if (value != null && value != "")
                {
                    string tmp = value;
                    this.textBox1.Text = tmp.Substring(0, 5);// value.Substring(0, 5);
                    this.textBox2.Text = tmp.Substring(5, 5);//value.Substring(5, 5);
                    this.textBox3.Text = tmp.Substring(10, 5);// value.Substring(10, 5);
                    this.textBox4.Text = tmp.Substring(15, 5);//value.Substring(15, 5);
                    this.textBox5.Text = tmp.Substring(20, 5);//value.Substring(20, 5);
                    this.textBox6.Text = tmp.Substring(25, 5);//value.Substring(0x19, 5);
                    this.textBox7.Text = tmp.Substring(30, 5);//value.Substring(30, 5);
                    this.textBox8.Text = tmp.Substring(0x23, 5);//value.Substring(0x23, 5);
                }
            }
        }

        public string TextToClipBoard
        {
            get
            {
                return (this.textBox1.Text + "-" + this.textBox2.Text + "-" + this.textBox3.Text + "-" + this.textBox4.Text + "-" + this.textBox5.Text + "-" + this.textBox6.Text + "-" + this.textBox7.Text + "-" + this.textBox8.Text);
            }
        }
    }
}

